package com.atguigu.dao.impl;

import com.atguigu.dao.ProjectDao;
import com.atguigu.pojo.Project;
import com.atguigu.pojo.Subtask;

import java.util.List;

public class ProjectDaoImpl extends BaseDao implements ProjectDao {
    @Override
    public int addProject(Project project) {
        System.out.println("ProjectDaoImpl程序在[" + Thread.currentThread().getName() + "]线程中");
        String sql = "insert into t_project(`id`,`name`) values(?,?);";
        return update(sql,project.getId(),project.getName());
    }
    @Override
    public int updateProject(Project project) {
        String sql = "update t_project set `name`=? where id=?";
        return update(sql,project.getName(), project.getId());
    }

    @Override
    public int deleteProjectById(String id) {
        String sql = "delete from t_project where id=?";
        return update(sql, id);
    }
    @Override
    public Project queryProjectByProjectName(String projectName) {
        String sql = "select `id`,`name` from t_project where name=?";
        return queryForOne(Project.class, sql, projectName);
    }

    @Override
    public Project queryProjectByProjectId(String id) {
        String sql = "select `id`,`name` from t_project where id=?";
        return queryForOne(Project.class, sql, id);
    }

    @Override
    public List<Project> queryProjects() {
        String sql = "select `id`,`name` from t_project";
        return queryForList(Project.class, sql);
    }
}
